package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 月签到
 */
public class SignCfg extends BaseCfg<SignCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "sign";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.SignCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 4;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","所属月","累计次数","包含奖励",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","month","signTimes","gifts",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","month","signTimes","gifts",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,104080000,1061242761,98352451,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","Map",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,Map.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 所属月
	 */
	private int month;
	
	/**
	 * 累计次数
	 */
	private int signTimes;
	
	/**
	 * 包含奖励
	 */
	private Map gifts;
	
	
	
	public static SignCfg builder() {
		SignCfg signCfg = new SignCfg();
		return signCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 所属月
	 */
	public int getMonth() {
		return month;
	}
	
	/**
	 * 累计次数
	 */
	public int getSignTimes() {
		return signTimes;
	}
	
	/**
	 * 包含奖励
	 */
	public Map getGifts() {
		return gifts;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.month;
        values[2] = this.signTimes;
        values[3] = this.gifts;
        return values;
	}
	
	protected SignCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.month = (int)vals[1];
		this.signTimes = (int)vals[2];
		this.gifts = (Map)vals[3];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.month);
        map.put(keys[2], this.signTimes);
        map.put(keys[3], this.gifts);
        return map;
    }
    
    protected SignCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.month = (int)map.get(keys[1]);
   		this.signTimes = (int)map.get(keys[2]);
   		this.gifts = (Map)map.get(keys[3]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.month);
        obj.put(keys[2], this.signTimes);
        obj.put(keys[3], this.gifts);
        return obj;
    }
    
    protected SignCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.month = obj.getIntValue(keys[1]);
	    this.signTimes = obj.getIntValue(keys[2]);
		this.gifts = obj.getObject(keys[3],Map.class);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.month);
	    byteBuf.writeInt(this.signTimes);
	    byteBuf.writeObject(this.gifts);
    }
	
	protected SignCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.month = byteBuf.readInt(null);
	    this.signTimes = byteBuf.readInt(null);
	    this.gifts = (Map)byteBuf.readObject();
	    return this;
	}
	
	public SignCfg deepCopy(){
		SignCfg signCfg = null;
		try {
			signCfg = (SignCfg) super.clone();
		    signCfg.gifts = ToolCopy.copyObject(this.gifts);
			return signCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return signCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
